fix(core): ObjectLogger file destination silently no-ops in ESM builds (#3110)#3116
Merged
Conversation
#3110) `openFileStream` loaded `fs` with a lazy `require()` to keep the browser-safe logger entry out of the `fs` bundle graph. esbuild rewrites that to its `__require` shim in the ESM output, which throws `Dynamic require of "fs" is not supported`, and the surrounding bare `catch {}` swallowed it. The workspace is `type: module`, so every Node ESM consumer — `os serve`, `os dev` — silently got no file logging at all, while the CJS build kept working. Load the builtin through `process.getBuiltinModule` instead: a plain method call, opaque to bundlers, working in both module systems, still behind the existing `typeof process` guard. `require` stays as a fallback for Node < 20.16, which predates it. A `file` destination that cannot be opened now reports on stderr rather than vanishing — the silence is what kept this hidden. Opening the destination for the first time also exposed three faults that were unreachable while it never opened: - `child()` passed `file` to the constructor, which opens eagerly, so every child opened a second stream to the same path and immediately orphaned it — despite the "no double-open" comment. - Destroying a child ended the stream its parent and siblings were still writing to. - `createWriteStream` reports open failures asynchronously; an 'error' event with no listener is an uncaught exception, so an unwritable log path would have taken the host process down. The regression test bundles the entry with esbuild and spawns a real `node`, because under vitest the source runs through vite-node where `require` IS defined — an in-process test of this code passes against the broken version. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 22 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
os-zhuang
added a commit
that referenced
this pull request
Jul 17, 2026
…-build-approvals comments (#3125) #3119 cited "#3110" in four comments as the pnpm 11 build-approvals bug. #3110 is an unrelated, already-closed issue — "ObjectLogger file destination silently no-ops in ESM builds" (fixed by #3116). The reference was fabricated: the pnpm 11 scaffold breakage was found while diagnosing the red Publish Smoke gate and has no issue of its own, so the correct citation is the PR that fixed it, #3119. Comment-only. It left a wrong pointer in the two places most likely to be read next: the "why is the smoke's pnpm unpinned" rationale in the script header, and the ratchet guarding the template. The template pnpm-workspace.yaml and the changeset never cited it, so nothing user-facing shipped with the bad reference. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3110.
What was broken
createLogger({ file })never wrote the file from an ESM entrypoint.openFileStreamloadedfswith a lazyrequire()to keepfsout of the browser bundle graph (the entry is deliberately browser-safe —@objectstack/clientbundles it). esbuild rewrites that to its__requireshim in the ESM output, which throwsDynamic require of "fs" is not supported, and the surrounding barecatch {}swallowed it.The workspace is
type: module, so this hit every Node ESM consumer —os serve,os dev— while the CJS build kept working. File logging has effectively never run in production.The fix
process.getBuiltinModule— a plain method call, so bundlers can't see it, working in both module systems, still behind the existingtypeof processguard.requirestays as a fallback for Node < 20.16, which predates it (enginesallows>=18, so CJS on old Node must not regress).filedestination that can't be opened now says so on stderr. The silence is precisely what kept this hidden, per the issue. It deliberately bypasseslevelfiltering: this reports that the logger cannot honour its own config, which isn't an application log event.Three faults this un-hid
Opening the destination for the first time made latent code reachable. Each is verified load-bearing by reverting it alone and watching the matching test go red:
child()fileinto the eager-opening constructor, then overwrote the streamno double-opencommentdestroy()'error'listenerThe third is the reason this isn't a one-line change: shipping only the
requirefix would have turned a silent no-op into a crash on a badfilepath.Verification
The issue's repro, against the built ESM dist:
Unwritable path — warns, keeps console logging, exits 0:
Also checked: browser safety holds (no static
fs/pathimport in the ESM dist;createLogger({file})with noprocessglobal doesn't throw),@objectstack/clientbuilds,@objectstack/core24/24 test files pass with--force, eslint clean.Note on the test
logger-esm-file.test.tsbundles the entry with esbuild and spawns a realnode. That indirection is load-bearing: under vitest the source runs through vite-node whererequireis defined, so an in-process test of this code passes against the broken version. It fails on all 4 assertions atorigin/main. It bundles rather than readingdist/becauseturbo'stestonlydependsOn: ["^build"](not its own build) and excludesdist/**from its inputs — adist-reading test would be both unbuilt and mis-cached. This addsesbuildto core's devDeps (already in the lockfile via tsup; pnpm's strict linking wouldn't resolve it otherwise).Rebased onto #3111, which landed on the same file and already makes the file destination plain-text — so no ANSI codes reach the now-working log file.
🤖 Generated with Claude Code